
#include "menu.h"

#include <QHBoxLayout>
#include <QIntValidator>
#include <QLabel>
#include <QDebug>


Menu::Menu(QWidget *parent)
    : QWidget(parent)
    , btChangeSize("重新生成地图")
{
    createUi();
    connectUi();
    connectSound();
//    connect(&btn_temp,&QPushButton::clicked,[=](){
//         QMessageBox::StandardButton mes3 = QMessageBox::information(NULL,"Error","Have you made the correct motor imagine?",QMessageBox::Yes|QMessageBox::No);
//    });
    connect(&btn_start,&QPushButton::click,[=]()
    {
             emit  noticSound();
    });
    connect(&btn_stop,&QPushButton::click,[=]()
    {
            emit   disconnectClient();
    });
    //connectRoad();
}

void Menu::createUi()
{
    btn_start.setText("Start");
    btn_stop.setText("Stop");
    QVBoxLayout *v=new QVBoxLayout(this);
    v->setSpacing(20);

    v->setAlignment(Qt::AlignTop);
    QHBoxLayout *h=new QHBoxLayout;
    h->addWidget(new QLabel("行数"));
    h->addWidget(&row);
    v->addLayout(h);
    h=new QHBoxLayout;
    h->addWidget(new QLabel("列数"));
    h->addWidget(&col);
    v->addLayout(h);
    v->addWidget(&btChangeSize);

    v->addWidget(&btn_start);

    v->addWidget(&btn_stop);
    //v->addWidget(&btn_temp);
    QIntValidator* iv=new QIntValidator;
    row.setValidator(iv);
    col.setValidator(iv);


    QVBoxLayout *tip=new QVBoxLayout;


    QLabel *start=new QLabel("\n\n\nYellow Block:Start point\n\nBlack Blocks:Barricades\n\nGreen Blocks:Destination");

    QFont ft;
    ft.setPointSize(10);
    QFont ft1;
    ft1.setPointSize(16);

    start->setFont(ft);
//    start->setStyleSheet("background: yellow;");
    tip->addWidget(start);

//    QLabel *end=new QLabel("鼠标右键设置终点");
//    end->setStyleSheet("background: green;");
//    tip->addWidget(end);

//    QLabel *block=new QLabel("鼠标中键设置路障");
//    block->setStyleSheet("background: blue;");
//    tip->addWidget(block);

    mytip = new QLabel("\n\n\nOrder:Left");
    QPalette pa;
    pa.setColor(QPalette::WindowText,Qt::red);
    mytip->setPalette(pa);
    mytip->setFont(ft1);
//    QLabel *mytip = new QLabel(tr("\n\n\nOrder:左"));
    tip->addWidget(mytip);



    v->addLayout(tip,0);

}

void Menu::connectUi()
{
    connect(&btChangeSize,&QPushButton::clicked,[=]()
    {
        emit changeSize(row.text().toInt(),col.text().toInt());
    });

    //mytip->setText("\n\n\nOrder:ight");

}
void Menu::connectSound()
{
    connect(&btn_start,&QPushButton::clicked,[=]()
    {

        emit noticSound();
        qDebug() << "hah" << endl;
        emit send_start();

    });
}
void Menu::setTips(int x)
{
    if(x==1)
    {
        mytip->setText("\n\n\nOrder:Left");
    }
    else if(x ==2)
    {
        mytip->setText("\n\n\nOrder:Right");
    }



}
